package org.viettan.android.main.activities.info;

import org.viettan.android.main.R;
import org.viettan.android.main.activities.common.VietTanBaseActivity;
import org.viettan.android.main.managers.SettingsManager;
import org.viettan.android.main.model.Language;

import roboguice.inject.InjectView;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;

import com.google.inject.Inject;

/**
 * Displays a choice for language.
 */
public class LanguageChoiceActivity extends VietTanBaseActivity {

    @Inject
    SettingsManager settingsManager;

    @InjectView(R.id.vietnamese)
    RadioButton vietnamese;

    @InjectView(R.id.english)
    RadioButton english;

    @InjectView(R.id.french)
    RadioButton french;

    @Override
    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.language_choice);

	Language currentLanguage = settingsManager.getArticleLanguage();
	english.setChecked(currentLanguage == Language.ENGLISH);
	vietnamese.setChecked(currentLanguage == Language.VIETNAMESE);
	french.setChecked(currentLanguage == Language.FRENCH);

	english.setOnClickListener(new OnClickListener() {
	    public void onClick(View v) {
		settingsManager.setArticleLanguage(Language.ENGLISH);
		finish();
	    }
	});

	french.setOnClickListener(new OnClickListener() {
	    public void onClick(View v) {
		settingsManager.setArticleLanguage(Language.FRENCH);
		finish();
	    }
	});

	vietnamese.setOnClickListener(new OnClickListener() {
	    public void onClick(View v) {
		settingsManager.setArticleLanguage(Language.VIETNAMESE);
		finish();
	    }
	});
    }
}
